package filter;


import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;


public class MyTextEncoder implements ProtocolEncoder
{
	private StringBuffer res = new StringBuffer();

	public void dispose(IoSession arg0) throws Exception
	{
	}

	public void encode(IoSession arg0, Object message, ProtocolEncoderOutput out)
			throws Exception
	{
		String msg = message.toString()+'\b';
//		res.append(msg);
//		String m = res.toString();
//		if(m.startsWith("<?xml version=\"1.0\"") && m.endsWith("</Name>"))
//		{
//			System.out.println("-------------------server -  "+m);
//			m+="\n";
//			byte[] bu = m.getBytes("UTF-8");
//			IoBuffer buffer = IoBuffer.wrap(bu);
//			out.write(buffer);
//			out.flush();
//			
//		}
		byte[] bu = msg.getBytes("UTF-8");
		IoBuffer buffer = IoBuffer.wrap(bu);
		out.write(buffer);
		out.flush();
	
	}

}
